/**
 * SequenceViewController
 * @Chunning.Xu
 * 2011 Nov 23, 2011 9:49:40 PM
 **/
package com.lux.product.controllers
{
	import com.greensock.TweenLite;
	import com.greensock.easing.Cubic;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.effects.Tween;
	
	public class SequenceViewController extends LuxViewController
	{
		//START.

		private var labels:Vector.<SequenceItemViewController>;
		
		public var btnShow:Sprite;
		public var container:Sprite;
		
		private const LABEL_OFFSET:Number = 4;
		
		public function SequenceViewController(view:Sprite)
		{
			super(view);
			
			btnShow.buttonMode = true;
			container.alpha = 1;
			container.visible = false;
			
			btnShow.addEventListener(MouseEvent.MOUSE_OVER,btnShowOverHandler);
			btnShow.addEventListener(MouseEvent.MOUSE_OUT,btnShowOutHandler);
		}
		
		private function btnShowOverHandler(evt:Event):void
		{
			TweenLite.killTweensOf(container);
			var index:int = 0;
			for each(var controller:SequenceItemViewController in labels)
			{
				controller.view.visible = true;
				controller.view.alpha = 0;
				controller.view.y = LABEL_OFFSET;
				
				TweenLite.killTweensOf(controller.view);
				TweenLite.to(controller.view,.5,{alpha:1,y:0,ease:Cubic.easeInOut,delay:index * 0.1});
				
				index ++;
			}
			
			container.visible = true;
			container.alpha = 1;
		}
		
		private function btnShowOutHandler(evt:Event):void
		{
			TweenLite.killTweensOf(container);
			TweenLite.to(container,0.5,{alpha:0,ease:Cubic.easeInOut,onComplete:function():void{container.visible = false}});
		}
		
		private var _sequence:Array;
		public function set sequence(list:Array):void
		{
			if(list == null || list == _sequence)
				return;
			this._sequence = list;

			while(container.numChildren > 0)
				container.removeChildAt(0);
			
			labels = new Vector.<SequenceItemViewController>;
			var index:int = 1;
			var startX:Number = 0;
			for each(var label:String in list)
			{
				var itemControler:SequenceItemViewController = new SequenceItemViewController;
				itemControler.setNumAndTitle(index,label);
				labels.push(itemControler);
				
				itemControler.view.x = startX;
				container.addChild(itemControler.view);
				startX = itemControler.view.getBounds(container).right; 
				
				if(index == list.length)
					itemControler.hideArrow();
				index ++;
			}
		}
		
		public function get sequence():Array
		{
			return _sequence;	
		}
		
		//END
	}
}